/*
Navicat MySQL Data Transfer

Source Server         : ROOT
Source Server Version : 50155
Source Host           : localhost:3306
Source Database       : db_wdidss

Target Server Type    : MYSQL
Target Server Version : 50099
File Encoding         : 65001

Date: 2012-10-01 23:21:27
*/

SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for `t_thing`
-- ----------------------------
DROP TABLE IF EXISTS `t_thing`;
CREATE TABLE `t_thing` (
`thingid`  int(11) NOT NULL AUTO_INCREMENT ,
`userid`  int(11) NOT NULL ,
`title`  text CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`status`  tinytext CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
`detail`  text CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
`time`  datetime NULL DEFAULT NULL ,
PRIMARY KEY (`thingid`),
FOREIGN KEY (`userid`) REFERENCES `t_user` (`userid`) ON DELETE CASCADE ON UPDATE RESTRICT
)
ENGINE=InnoDB
DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
/*!50003 AUTO_INCREMENT=1 */

;

-- ----------------------------
-- Records of t_thing
-- ----------------------------
BEGIN;
COMMIT;

-- ----------------------------
-- Table structure for `t_token`
-- ----------------------------
DROP TABLE IF EXISTS `t_token`;
CREATE TABLE `t_token` (
`tokenid`  int(11) NOT NULL AUTO_INCREMENT ,
`userid`  int(11) NOT NULL ,
`token`  tinytext CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`time`  datetime NOT NULL ,
PRIMARY KEY (`tokenid`),
FOREIGN KEY (`userid`) REFERENCES `t_user` (`userid`) ON DELETE CASCADE ON UPDATE RESTRICT
)
ENGINE=InnoDB
DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
/*!50003 AUTO_INCREMENT=1 */

;

-- ----------------------------
-- Records of t_token
-- ----------------------------
BEGIN;
COMMIT;

-- ----------------------------
-- Table structure for `t_update`
-- ----------------------------
DROP TABLE IF EXISTS `t_update`;
CREATE TABLE `t_update` (
`updateid`  int(11) NOT NULL AUTO_INCREMENT ,
`userid`  int(11) NOT NULL ,
`thingid`  int(11) NOT NULL ,
`type`  tinytext CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`time`  datetime NOT NULL ,
PRIMARY KEY (`updateid`)
)
ENGINE=InnoDB
DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
/*!50003 AUTO_INCREMENT=1 */

;

-- ----------------------------
-- Records of t_update
-- ----------------------------
BEGIN;
COMMIT;

-- ----------------------------
-- Table structure for `t_user`
-- ----------------------------
DROP TABLE IF EXISTS `t_user`;
CREATE TABLE `t_user` (
`userid`  int(11) NOT NULL AUTO_INCREMENT ,
`username`  tinytext CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`truename`  tinytext CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
`password`  tinytext CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`time`  datetime NULL DEFAULT NULL ,
PRIMARY KEY (`userid`)
)
ENGINE=InnoDB
DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
/*!50003 AUTO_INCREMENT=1 */

;

-- ----------------------------
-- Records of t_user
-- ----------------------------
BEGIN;
COMMIT;

-- ----------------------------
-- Indexes structure for table `t_thing`
-- ----------------------------
CREATE INDEX `userid` USING BTREE ON `t_thing`(`userid`);
DELIMITER ;;
CREATE TRIGGER `tg_wheninsert` AFTER INSERT ON `t_thing` FOR EACH ROW insert into t_update(userid,thingid,type,`time`) values(NEW.userid,NEW.thingid,'insert',now())
;;
DELIMITER ;
DELIMITER ;;
CREATE TRIGGER `tg_whenmodify` AFTER UPDATE ON `t_thing` FOR EACH ROW insert into t_update(userid,thingid,type,`time`) values(OLD.userid,OLD.thingid,'modify',now())
;;
DELIMITER ;
DELIMITER ;;
CREATE TRIGGER `tg_whendelete` AFTER DELETE ON `t_thing` FOR EACH ROW insert into t_update(userid,thingid,type,`time`) values(OLD.userid,OLD.thingid,'delete',now())
;;
DELIMITER ;

-- ----------------------------
-- Auto increment value for `t_thing`
-- ----------------------------
ALTER TABLE `t_thing` AUTO_INCREMENT=1;

-- ----------------------------
-- Indexes structure for table `t_token`
-- ----------------------------
CREATE INDEX `userid` USING BTREE ON `t_token`(`userid`);

-- ----------------------------
-- Auto increment value for `t_token`
-- ----------------------------
ALTER TABLE `t_token` AUTO_INCREMENT=1;

-- ----------------------------
-- Indexes structure for table `t_update`
-- ----------------------------
CREATE INDEX `userid` USING BTREE ON `t_update`(`userid`);
CREATE INDEX `thingid` USING BTREE ON `t_update`(`thingid`);

-- ----------------------------
-- Auto increment value for `t_update`
-- ----------------------------
ALTER TABLE `t_update` AUTO_INCREMENT=1;

-- ----------------------------
-- Auto increment value for `t_user`
-- ----------------------------
ALTER TABLE `t_user` AUTO_INCREMENT=1;
